<?php
/**
 * Created by PhpStorm.
 * User: cephei
 * Date: 12/10/15
 * Time: 11:12 AM
 */

namespace Plugins\WebInterface;


use Core\PluginContainer;

class Plugin_WebInterface{
    public function injectRoute(){
        $routeJson = file_get_contents(ROOT_PATH.'/Storage/Configs/webinterface.json');
        $routes = json_decode($routeJson);
        $modulesJson = file_get_contents(ROOT_PATH."/Configs/Modules.json");
        $modules = json_decode($modulesJson);
        $router = PluginContainer::getInstance()->singletonMake('route');
        if($router==null){
            PluginContainer::getInstance()->make('log')->levelLog("Plugin - router not found *Plugin_WebInterface","error");
            return;
        }
        foreach($modules as $module){
            $pluginName = $module->name;
            $pluginRoutes = $routes->$pluginName;
            if(!empty($pluginRoutes)){
                foreach($pluginRoutes as $pluginRoute){
                    if(!$router->checkRoutePoint($pluginRoute->url,$pluginRoute->httpmethod)){
                        $router->registerWay($pluginRoute->url,$pluginRoute->httpmethod,$pluginRoute->point);
                    }
                }
            }

        }
    }
}